home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 58606 / 58606.xpi / chrome / translator.jar / content / translatorLoader.js < prev    next >
Text File  |  2010-02-07  |  3KB  |  93 lines

  1.  
  2. // declaring jQuery variable
  3. var translatorJQuery = jQuery.noConflict(true);
  4.  
  5. // initializing package namespace
  6. if(!com) var com = {};
  7. if(!com.igorgladkov) com.igorgladkov = {};
  8. if(!com.igorgladkov.translator) com.igorgladkov.translator = {};
  9.  
  10. (function(namespace, $)
  11. {
  12.     namespace.TranslatorLoader = function()
  13.     {
  14.         // empty costructor
  15.     };
  16.     
  17.     namespace.TranslatorLoader.prototype = {
  18.         translator: null,
  19.         ui: null,
  20.         prefs: null,
  21.         properties: null,
  22.         
  23.         load: function()
  24.         {
  25.             var appcontent = document.getElementById('appcontent');
  26.             
  27.             if(!appcontent) return;
  28.             
  29.             if(!appcontent.translator) {
  30.                 appcontent.translator = true;
  31.                 
  32.                 // start prefs manager
  33.                 this.prefs = new namespace.PrefsManager();
  34.                 
  35.                 // get properties
  36.                 this.properties = $('#translator-properties').get(0);
  37.                 
  38.                 // create translator ui
  39.                 this.ui = new namespace.TranslatorUI();
  40.                 
  41.                 // create translator
  42.                 this.translator = new namespace.Translator(this.prefs, this.ui);
  43.                 this.translator.init();
  44.                 
  45.                 appcontent.addEventListener('DOMContentLoaded', this.pageLoadedHandler.bind(this), false);
  46.             }
  47.             
  48.             this.checkUpdateStatus();
  49.         },
  50.         
  51.         checkUpdateStatus: function(e)
  52.         {
  53.             // get installed version
  54.             var extensionManager = Components.classes['@mozilla.org/extensions/manager;1'].getService(Components.interfaces.nsIExtensionManager);
  55.             var installedVersion = extensionManager.getItemForID('{5C655500-E712-41e7-9349-CE462F844B19}').version;
  56.             
  57.             // get saved version from preferences (null if add-on was just installed)
  58.             var savedVersion = this.prefs.getPref('_version') || -1;
  59.             
  60.             // if extension was updated
  61.             if(installedVersion != savedVersion) {
  62.                 this.prefs.setPref('_version', installedVersion, 32/*string*/);
  63.                 
  64.                 // load webpage if translator was installed for the first time or updated
  65.                 window.setTimeout(function() {
  66.                     gBrowser.selectedTab = gBrowser.addTab('http://igorgladkov.com/extensions/translator.html');
  67.                 }, 1000);
  68.             }
  69.         },
  70.         
  71.         pageLoadedHandler: function(e)
  72.         {
  73.             // initialize new page
  74.             var page = new namespace.Page(this.translator, this.properties);
  75.             page.init(e.originalTarget);
  76.         }
  77.     };
  78.     
  79.     // load event listener
  80.     $(window).one('load.translator', function() {
  81.         var translatorLoader = new namespace.TranslatorLoader();
  82.         translatorLoader.load();
  83.     }, false);
  84.     
  85.     // binding function
  86.     Function.prototype.bind = function(o) {
  87.         var m = this;
  88.         
  89.       return function() {
  90.         return m.apply(o, arguments);
  91.       };
  92.     }
  93. })(com.igorgladkov.translator, translatorJQuery);